package com.guigu.basedservice.controller;


import com.guigu.basedservice.entity.BaseCarTypePartsSku;
import com.guigu.basedservice.service.BaseCarTypePartsSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 车型配件关联表 前端控制器
 * </p>
 *
 * @author Heyuhang
 * @since 2024-09-20
 */
@CrossOrigin
@RestController
@RequestMapping("/basedservice/base-car-type-parts-sku")
public class BaseCarTypePartsSkuController {

    @Autowired
    private BaseCarTypePartsSkuService baseCarTypePartsSkuService;

    @RequestMapping("/partsSave")
    public boolean add(@RequestBody BaseCarTypePartsSku baseCarTypePartsSku){
        List<String> partUuidList  = baseCarTypePartsSku.getPartUuid();
        for (String partUuid  : partUuidList){
            BaseCarTypePartsSku baseCarTypePartsSku1 = new BaseCarTypePartsSku();
            baseCarTypePartsSku1.setCarTypeUuid(baseCarTypePartsSku.getCarTypeUuid());
            baseCarTypePartsSku1.setPartUuid(Collections.singletonList(partUuid)); // 设置单个partUuid
        }
        System.out.println("baseCarTypePartsSku++++"+baseCarTypePartsSku);
        boolean save = baseCarTypePartsSkuService.save(baseCarTypePartsSku);
        if(save){
            return true;
        }
        return false;
    }

    @RequestMapping("/partsSave2")
    public boolean add2(@RequestBody BaseCarTypePartsSku baseCarTypePartsSku){
        System.out.println("baseCarTypePartsSku++++"+baseCarTypePartsSku);
        boolean save = baseCarTypePartsSkuService.insertBaseCarTypePartsSku(baseCarTypePartsSku);
        if(save){
            return true;
        }
        return false;
    }
}

